<!-- 生产数据趋势图 -->
<script lang="ts" setup>
import MyChart from '@/components/MyChart.vue'
import { ref, watch } from 'vue'
const props = defineProps(['data'])

const options = ref({
  grid: {
    // top: 20,
    left: 60,
    right: 20,
  },
  tooltip: {
    trigger: 'axis',
    confine: true,
    axisPointer: {
      type: 'shadow',
      crossStyle: {
        color: '#999'
      }
    }
  },
  legend: {
    show: true,
    right: 20,
    icon: 'circle',
    textStyle: {
      color: '#ebeef5',
      fontSize: 20,
    },
    data: []
  },
  xAxis: [
    {
      type: 'category',
      // boundaryGap: false,
      data: [],
      axisPointer: {
        type: 'shadow'
      },
      axisLabel: {
        color: '#ebeef5',
        fontSize: 16,
        interval: 0, rotate: 30
      },
      axisTick: {
        show: false
      },
      axisLine: {
        show: true,
        lineStyle: {
          color: '#182758',
          width: 1
        }
      }
    }
  ],
  yAxis: [
    {
      type: 'value',
      name: '%',
      nameTextStyle: {
        color: 'rgba(255,255,255,0.85)',
        fontSize: 16,
        align: 'right',
        padding: [0, 5, 8, 0]
      },
      axisLabel: {
        formatter: '{value}',
        color: '#ebeef5',
        fontSize: 16,
        align: 'right'
      },
      axisLine: {
        show: false,
        lineStyle: {
          color: '#182758',
          width: 2
        }
      },
      splitLine: {
        show: true,
        lineStyle: {
          color: '#182758',
          width: 1
        }
      }
    }
  ],
  series: [
    {
      name: '',
      type: 'line',
      color: '#00B8A9',
      smooth: true,
      symbol: 'true',
      showSymbol: false,
      lineStyle: {
        color: '#00B8A9',
        width: 2,
        shadowColor: 'rgba(0, 184, 169, 0.3)',
        shadowBlur: 10,
        shadowOffsetY: 5
      },
      areaStyle: {
        color: {
          type: 'linear',
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [
            { offset: 0, color: 'rgba(0, 184, 169, 0.4)' },
            { offset: 1, color: 'rgba(0, 184, 169, 0)' }
          ]
        }
      },
      //   yAxisIndex: 1,
      tooltip: {
        valueFormatter: function (value: any) {
          return value + ''
        }
      },
      data: []
      
    }
  ]
})

watch(
  () => props.data,
  (val) => {
    const {legendList, xList, yList } = val
    options.value.legend.data = legendList
    options.value.xAxis[0].data = xList
    options.value.series[0].name = legendList[0]
    options.value.series[0].data = yList
  },
  {
    deep: true, // 开启深度监听
    immediate: true // 立即触发一次（可选）
  }
)
</script>
<template>
  <MyChart height="220px" :option="options" />
</template>
